#include "NetworkModule.h"
#include <string>
#include <ut_debug.h>
#include <common.h>
#include <xml.h>
#include "PipeManager.h"

using namespace std;
using namespace utility::system;
using namespace utility::xml;

#pragma comment(lib, "net_module.lib")
#pragma comment(lib, "pipe_module.lib")
#pragma comment(lib, "system.lib")
#pragma comment(lib, "strutil.lib")

CNetworkModule::CNetworkModule(void)
{
    m_pNetModule = get_net_module();
    m_pPipeModule = get_pipe_module();
}


CNetworkModule::~CNetworkModule(void)
{
    destroy_net_module();
    destroy_pipe_module();
}

bool CNetworkModule::Init()
{
    string strPipeConfigFile = utility::system::get_exe_path();
    strPipeConfigFile += "/DBPipeConfig.xml";
    if (!m_pPipeModule->initialize(strPipeConfigFile.c_str(), CPipeManager::Instance(), m_pNetModule))
    {
        LOG(CRITICAL) << "Failed on initializing pipe module";
        return false;
    }

    return true;
}

bool CNetworkModule::Run()
{
    if (m_pNetModule)
        return m_pNetModule->run() > 0;
    return false;
}
